<!-- 普通员工界面(可删除) -->
<template>
	<el-row>
		<el-col :span="9">
			<el-form ref="form" :rules="rules" :model="form" label-width="80px">
				<el-form-item label="编号" prop="id">
					<el-input v-model="form.id" disabled></el-input>
				</el-form-item>
				<el-form-item label="姓名" prop="name">
					<el-input v-model="form.name"></el-input>
				</el-form-item>
				<el-form-item label="年龄" prop="age">
					<el-input v-model="form.age"></el-input>
				</el-form-item>
				<el-form-item label="手机号" prop="phone">
					<el-input v-model="form.phone"></el-input>
				</el-form-item>
				<el-form-item label="学历" prop="eduBg">
					<el-input v-model="form.eduBg" ></el-input>
				</el-form-item>
<!-- 				<el-form-item label="入职日期" prop="date" >
					<el-input v-model="form.date" disabled></el-input>
				</el-form-item> -->


				<el-form-item>
					<el-button type="primary" @click="send()">保存</el-button>
				</el-form-item>

			</el-form>
		</el-col>
	</el-row>


</template>
<script>
	export default {
		data() {
			var validatePass = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请输入密码'));
				} else {
					if (this.ruleForm.checkPass !== '') {
						this.$refs.ruleForm.validateField('checkPass');
					}
					callback();
				}
			};
			var validatePass2 = (rule, value, callback) => {
				if (value === '') {
					callback(new Error('请再次输入密码'));
				} else if (value !== this.ruleForm.pass) {
					callback(new Error('两次输入密码不一致!'));
				} else {
					callback();
				}
			};

			return {
				formLabelWidth: "100px",
				dialogFormVisible: false,
				num: sessionStorage.getItem("num"),
				form: {
					id: '',
					name: '',
					age: '',
					phone: '',
					eduBg: '',
					date: ''

				},
				ruleForm: {
					phone: sessionStorage.getItem("num"),
					psw: '',
					pass: '',
					checkPass: '',
				},
				rules: {
					adminPhone: [{
							required: true,
							message: '请输入电话',
							trigger: 'blur'
						},
						{
							min: 11,
							max: 11,
							message: '请输入正确的电话格式',
							trigger: 'blur'
						}
					],
					adminEmail: [{
							required: true,
							message: '请输入邮箱地址',
							trigger: 'blur'
						},
						{
							type: 'email',
							message: '请输入正确的邮箱地址',
							trigger: ['blur', 'change']
						}
					],
					pass: [{
						validator: validatePass,
						trigger: 'blur'
					}],
					checkPass: [{
						validator: validatePass2,
						trigger: 'blur'
					}]

				}
			}

		},
		methods: {

			send() {
				var that = this;
				this.$http.post("/RegisterUser/updateRegUser/", this.form).then(function(res) {
					console.log(res);
					if (res.data == "ok") {
						that.$message({
							message: '更新成功!',
							type: 'success'
						});
					} else if (res.data == "no") {
						that.$message({
							message: '更新失败!',
							type: 'warning'
						});
					} else {
						this.$message({
							type: 'error',
							message: '未知错误!!'
						});
					}
				})
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.$axios.post("/changePassword", this.ruleForm).then(res => {
							if (res.data == "502") {
								this.$message({
									message: '密码错误,请重新输入',
									type: 'error'
								});
								this.resetForm(formName);
							} else {
								this.$message({
									message: '密码修改成功,请重新登录',
									type: 'success'
								});
								sessionStorage.clear();
								this.$router.push("/login");
							}
						})
					} else {
						this.$message({
							message: '请更改错误',
							type: 'success'
						})
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			}
		},
		created() {
			var that = this;

			console.log(this.num);
			// findMenuList  AdminByNum
			this.$http.post("/RegisterUser/findUserList").then(function(res) {
				console.log(res.data);
				console.log(res.regUser);
				that.form.id = res.data.regUser.id;
				that.form.name = res.data.regUser.name;
				that.form.age = res.data.regUser.age;
				that.form.phone = res.data.regUser.phone;
				that.form.eduBg = res.data.regUser.eduBg;
				that.form.date = res.data.regUser.date;
			})
		}


	}
</script>
